package cn.com.guage.dtm.mapping.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.com.guage.dtm.common.annotation.Log;
import cn.com.guage.dtm.common.enums.BusinessType;
import cn.com.guage.dtm.mapping.domain.MappingTableInfo;
import cn.com.guage.dtm.mapping.service.IMappingTableInfoService;
import cn.com.guage.dtm.common.core.controller.BaseController;
import cn.com.guage.dtm.common.core.domain.AjaxResult;
import cn.com.guage.dtm.common.utils.poi.ExcelUtil;
import cn.com.guage.dtm.common.core.page.TableDataInfo;

/**
 * 表级映射信息Controller
 * 
 * @author liujun
 * @date 2021-07-14
 */
@Controller
@RequestMapping("/mapping/table")
public class MappingTableInfoController extends BaseController
{
    private String prefix = "mapping/table";

    @Autowired
    private IMappingTableInfoService mappingTableInfoService;

    @RequiresPermissions("mapping:table:view")
    @GetMapping()
    public String table()
    {
        return prefix + "/table";
    }

    /**
     * 查询表级映射信息列表
     */
    @RequiresPermissions("mapping:table:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MappingTableInfo mappingTableInfo)
    {
        startPage();
        List<MappingTableInfo> list = mappingTableInfoService.selectMappingTableInfoList(mappingTableInfo);
        return getDataTable(list);
    }

    /**
     * 导出表级映射信息列表
     */
    @RequiresPermissions("mapping:table:export")
    @Log(title = "表级映射信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MappingTableInfo mappingTableInfo)
    {
        List<MappingTableInfo> list = mappingTableInfoService.selectMappingTableInfoList(mappingTableInfo);
        ExcelUtil<MappingTableInfo> util = new ExcelUtil<MappingTableInfo>(MappingTableInfo.class);
        return util.exportExcel(list, "表级映射信息数据");
    }

    /**
     * 新增表级映射信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存表级映射信息
     */
    @RequiresPermissions("mapping:table:add")
    @Log(title = "表级映射信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MappingTableInfo mappingTableInfo)
    {
        return toAjax(mappingTableInfoService.insertMappingTableInfo(mappingTableInfo));
    }

    /**
     * 修改表级映射信息
     */
    @GetMapping("/edit/{tableId}")
    public String edit(@PathVariable("tableId") Long tableId, ModelMap mmap)
    {
        MappingTableInfo mappingTableInfo = mappingTableInfoService.selectMappingTableInfoById(tableId);
        mmap.put("mappingTableInfo", mappingTableInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存表级映射信息
     */
    @RequiresPermissions("mapping:table:edit")
    @Log(title = "表级映射信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MappingTableInfo mappingTableInfo)
    {
        return toAjax(mappingTableInfoService.updateMappingTableInfo(mappingTableInfo));
    }

    /**
     * 删除表级映射信息
     */
    @RequiresPermissions("mapping:table:remove")
    @Log(title = "表级映射信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mappingTableInfoService.deleteMappingTableInfoByIds(ids));
    }
}
